class Solution {
public:
    long long func(int x) { return x * x + x; }


    int combine(int single, int odd)
    {
        if (single > odd) return odd * 2 + 1;
        else return single * 2;
    }


    int maxHeightOfTriangle(int red, int blue)
    {
        if (red < 1 || blue < 1) return 0;

        int red_s = sqrt(red);
        int blue_s = sqrt(blue);

        int red_o = 0, blue_o = 0;

        if (func(red_s) <= red) red_o = red_s;
        else red_o = red_s - 1;

        if (func(blue_s) <= blue) blue_o = blue_s;
        else blue_o = blue_s - 1;


        int count1 = combine(red_s, blue_o);
        int count2 = combine(blue_s, red_o);
        return count1 > count2 ? count1 : count2;
    }
};